home *** CD-ROM | disk | FTP | other *** search
/ Merciful 2 / Merciful - Disc 2.iso / software / l / lzxrepackerv2.04.lha / LZX_Repacker / LHA2LZX < prev    next >
Text File  |  1995-12-13  |  6KB  |  172 lines

  1. /*
  2.     $VER: LHA-LZX REPACK V2.04   Updated by Christer Bjarnemo (1995/12/13)
  3.  */
  4.  
  5. TempDir        = 'HD1:TRASHCAN/'
  6. Mode        = '3'
  7. Priority    = -1
  8. VirtualDisk    = 'FM0:'
  9.  
  10. /*************************************************/
  11. /* I recommend you leave it alone from here. :-) */
  12. /*************************************************/
  13.  
  14. Arg Dir arg1 arg2 arg3 arg4
  15.  
  16. forcelzx = 0
  17. LZXStore = TempDir
  18. TempDir = TempDir'_LZX_TEMP/'
  19. If ~EXISTS(TempDir) then address COMMAND 'makedir 'left(TempDir,length(TempDir)-1)
  20.  
  21. PATTERN = '.LZH|.LHA|.ZIP|.ARJ|.ARC|.ZOO|.GZ|.Z'
  22.  
  23. say 
  24. say 'LHA-LZX repacker 2.04  updated by Christer Bjarnemo 1995-12-13.'
  25. say 'Original program by Mat Bettinson of the Plot Hatching Factory.'
  26. say
  27.  
  28. if upper(arg1) = 'FORCELZX' | upper(arg2)='FORCELZX' | upper(arg3)='FORCELZX' | upper(arg4)='FORCELZX' then ForceLZX = 1
  29. if upper(arg1) = 'KEEPOLD' | upper(arg2)='KEEPOLD' | upper(arg3)='KEEPOLD' | upper(arg4)='KEEPOLD' then KEEPOLD = 'YES'
  30. if upper(arg1) = 'ONLYLHA' | upper(arg2)='ONLYLHA' | upper(arg3)='ONLYLHA' | upper(arg4)='ONLYLHA' then PATTERN = '.LZH|.LHA'
  31. if upper(arg1) = 'DMS' | upper(arg2)='DMS' | upper(arg3)='DMS' | upper(arg4)='DMS' then PATTERN = PATTERN'|.DMS'
  32.  
  33. If Dir = '?' | Dir = '/?' | Dir = '-?' | Dir = '' then signal Usage
  34.  
  35. If dir = '22'x'22'x then do
  36.     dir = '22'x'22'x
  37.     address command 'assign CDIR: 'dir
  38.     dir = 'CDIR:'
  39.     end
  40.  
  41. If ~EXISTS(Dir) then signal Usage
  42. say
  43. Call Pragma('S',50000)
  44. If right(Dir,1) ~= '/' & right(Dir,1) ~= ':' then Dir = Dir'/'
  45. Address COMMAND 'Assign REPACK: 'Tempdir
  46. Call Pragma('D','REPACK:')
  47. Address COMMAND 'List 'Dir' PAT #?('PATTERN') FILES LFORMAT "%n %c" >t:LHA-LZX.temp'
  48. Call Open(list,'t:LHA-LZX.temp','R')
  49. BSave = 0
  50. DO forever
  51.  Line = ReadLN(list)
  52.  File = strip(word(line,1)) ; Comment = strip(word(line,2)) ; Comment = Strip(Comment,'B','"')
  53.  IF EOF(list) then break
  54.  NewFile = Left(File,Length(file)-length(ext(file)))'LZX'
  55.  
  56.  say 'Converting file: 'File
  57.  Address COMMAND 'Delete >NIL: REPACK:#? ALL FORCE'
  58.  Call Open(ts,Dir||file) ; Lhasize = Seek(ts,0,'E') ; Call Close(ts)
  59.  
  60. /* Now we are going to extract the archive */
  61.  
  62. if ext(file)='LHA' then Address COMMAND 'LHA -a -F -M -P'Priority' x 'Dir||File' #? REPACK:'
  63. if ext(file)='ZIP' then Address COMMAND 'UnZip 'Dir||File' -d REPACK:'
  64.  
  65. if ext(file)='DMS' then do
  66.     Address command 'format >NIL: <NIL: drive 'VirtualDisk' name Empty quick noicons'
  67.     Address COMMAND 'unDMS <NIL: write 'Dir||File' to 'VirtualDisk' NOPAUSE NOTEXT'
  68.         Address COMMAND 'Copy >NIL: FM0:#? all to REPACK:'
  69.     end
  70.  
  71. if ext(file)='ARJ' then Address COMMAND 'UnARJ x 'Dir||File' REPACK:'
  72. if ext(file)='ARC' then do
  73.     Pragma('D','REPACK:')
  74.     Address COMMAND 'ARC x 'Dir||File
  75.     end
  76. if ext(file)='ZOO' then do
  77.     Pragma('D','REPACK:')
  78.     Address COMMAND 'ZOO eq/ 'Dir||File
  79.     end
  80. if ext(file)='GZ'  then Address COMMAND 'GZIP 'Dir||left(file,length(file)-1-length(ext(file)))' -cdN >REPACK:'left(file,length(file)-1-length(ext(file)))
  81. if ext(file)='Z' then Address COMMAND 'uncompress 'Dir||left(file,length(file)-1-length(ext(file)))' -c >REPACK:'left(file,length(file)-1-length(ext(file)))
  82.  
  83.  if RC ~= 0 then do
  84.     say ''
  85.     say 'WARNING! Something went wrong while unpacking 'file'.'
  86.     say 'The 'ext(file)' file could be corrupt, or (hopefully) there wasnt enough'
  87.     say 'space left on your hd/ramdisk.'
  88.     call writech(stdout,'Do you want to continue? (some files might be LOST forever) (y/N) ')
  89.     parse pull choice
  90.     if upper(choice) ~= 'Y' then do
  91.         exit(20)
  92.         end
  93.     end
  94.  
  95.  Address COMMAND 'LZX -r -e -M5000 -'Mode' -P'Priority' -F a 'LZXStore||NewFile' REPACK:#?'
  96.  
  97.  if RC ~= 0 then do
  98.     fel = 1
  99.     say ''
  100.     say 'WARNING! Something went wrong while packing 'LZXStore||newfile'.'
  101.     call writech(stdout,'Do you want to continue? (keeps the 'ext(file)' file) (y/N) ')
  102.  
  103.     parse pull choice
  104.     if upper(choice) ~= 'Y' then do
  105.         Address COMMAND 'Delete >NIL: 'LZXStore||newfile
  106.         say 'The original file 'file' is untouched :-)'
  107.         exit(20)
  108.         end
  109.     end
  110.  
  111. if fel ~= 1 then do
  112.  Call Open(ts,LZXStore||NewFile) ; Lzxsize = Seek(ts,0,'E') ; Call Close(ts)
  113.  Diff = Lhasize - Lzxsize
  114.  If Diff > 0 | ForceLZX then DO
  115.   if KEEPOLD ~= 'YES' then Address COMMAND 'Delete >NIL: 'Dir||File
  116.   If Comment ~= '' then Address COMMAND 'Filenote 'LZXStore||NewFile' "'Comment'"'
  117.   Address COMMAND 'Copy 'LZXStore||newfile' to 'dir
  118.  
  119.  if RC ~= 0 then do
  120.     say ''
  121.     say 'WARNING! Something went wrong while copying 'newfile' to 'dir'.'
  122.     call writech(stdout,'Do you want to continue? (the archive will be LOST forever) (y/N) ')
  123.     parse pull choice
  124.     if upper(choice) ~= 'Y' then do
  125.         say 'You should copy the file 'LZXStore||newfile' to a SAFE place.'
  126.         exit(20)
  127.         end
  128.     end
  129.  
  130.   Address COMMAND 'Delete >NIL: 'LZXStore||newfile
  131.   say '* 'Diff' bytes saved on this archive!' ; say
  132.   END
  133.  ELSE DO
  134.   Address COMMAND 'Delete >NIL: 'LZXStore||Newfile
  135.     say '* 'ext(file)' file 'ABS(Diff)' bytes larger than LZX. Keeping 'ext(file)'...' ; say
  136.   Diff = 0
  137.   END
  138.  BSave = BSave + Diff
  139. end
  140. else say '* Keeping 'ext(file)'...'
  141. end
  142.  
  143. Call Close(list)
  144. Address COMMAND 'Delete >NIL: REPACK:#? ALL FORCE'
  145. Address COMMAND 'Assign REPACK: REMOVE'
  146. Address COMMAND 'Assign CDIR: REMOVE'
  147.  
  148. say
  149. say ' *** LHA-LZX Repacker finished. 'Bsave' bytes saved in this dir. ***'
  150. say
  151. EXIT
  152.  
  153. Usage:
  154. say 'Usage: LHA2LZX <Directory> [options]'
  155. say
  156. say '  ForceLZX  Allways keep the LZX file even if the LHA file is smaller'
  157. say '  KeepOLD   Keep both LhA/ZIP and the LZX file'
  158. say '  OnlyLHA   Only repack LHA files'
  159. say '  DMS       Repack DMS archives'
  160. say
  161. say 'HINT: Replace <directory> with "" if you want to repack current dir.'
  162. say
  163. EXIT
  164.  
  165. ext: procedure
  166.   arg filename
  167.   do i=1 to length(filename)
  168.      if upper(substr(filename,length(filename)-i,1)) = '.' then break
  169.   end
  170.      extension = upper(right(filename,i))
  171. return(extension)
  172.